/**
 * Copyright (c) 2015-2030 by Beijing Yanlight Co., Ltd.
 * All rights reserved.
 */
package com.yanlight.support;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * 
 *
 * @author haolw
 * @time 2017/06/27
 */
public class SystemSupportListener implements ServletContextListener {
	private final String LOG4J_CONFIG_KEY = "log4j.configurationFile";
	private final String LOG4J_CONFIG_PATH = "../config/log4j2.xml";

	@Override
	public void contextInitialized(ServletContextEvent event) {
		init(event);
	}

	protected void init(ServletContextEvent event) {
		cacheContext(event);
		initLogConfig();
	}

	protected void initLogConfig() {
		System.setProperty(LOG4J_CONFIG_KEY, LOG4J_CONFIG_PATH);
	}

	protected void cacheContext(ServletContextEvent event) {
		ServletContextSupport.servletContext = event.getServletContext();
	}

	@Override
	public void contextDestroyed(ServletContextEvent event) {

	}

}
